<!-- 
 @Author: LW  
 @Date: 2021-01-08 11:30:38  
 @function: 角色编辑框
 -->
<template>
  <div>
    <!-- ref相当于Id:model是表单内容-->
    <el-form label-width="120px" ref="modifyInfo" :rules="formInfoRules" :model="formInfo">
      <el-row>
        <el-form-item label="参数名称：" prop="name">
          <el-input v-model="formInfo.name" autocomplete="off" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="参数键名：">
          <el-input   v-model="formInfo.parameters_key" autocomplete="off" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="参数键值：">
          <el-input   v-model="formInfo.parameters_value" autocomplete="off" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="排列顺序：">
          <el-input  type="number" v-model="formInfo.sort"  autocomplete="off" size="mini"></el-input>
        </el-form-item>
       
        <el-form-item label="备注信息：" >
          <el-input
            type="textarea"
            v-model="formInfo.remarks"
            rows="3"
            autocomplete="off"
            maxlength="200"
            show-word-limit
            size="mini"
          ></el-input>
        </el-form-item>
      </el-row>
    </el-form>
    <div slot="footer " class="el-dialog__footer">
      <el-button size="mini" @click="closeDialog()">取消</el-button>
      <el-button size="mini" type="primary" :loading="loading" @click="submitForm('modifyInfo')">保存</el-button>
    </div>
  </div>
</template>
<script>

import ParameterHttp from "@/api/basic/parameter"; //http
//定义变量
const {
   addInfo,//增加数据
   modifyInfo,//编辑数据
} = ParameterHttp;

export default {
  //组件实例的作用域是孤立的。这意味着不能 (也不应该) 在子组件的模板内直接引用父组件的数据。要让子组件使用父组件的数据，需要通过子组件的 props 选项
  //在模板中，要动态地绑定父组件的数据到子模板的 props，与绑定到任何普通的HTML特性相类似，就是用 v-bind。每当父组件的数据变化时，该变化也会传导给子组件
  props: ["formInfo"], //父界面v-bind:editInfo一致
  components: {
  },
  data() {
    return {
      loading: false, //是显示加载
      //验证对象，由Rules结尾
      formInfoRules: {
        name: [
          {
            required: true,
            min: 1,
            max: 20,
            message: "参数名称不能为空，最大长度为20",
            trigger: "blur"
          }
        ]
      }
    };
  },
  /**html加载完成之前，执行。执行顺序：父组件-子组件 */
  created() {},
  /**[页面初始化方法]html加载完成后执行。执行顺序：子组件-父组件*/
  mounted() {
  },
  methods: {
    //关闭增加弹出框
    closeDialog() {
      this.$emit("callBack", null);
    },
    //保存信息
    submitForm(modifyRef) {
      let self = this;
      this.$refs[modifyRef].validate(valid => {
        if (valid) {
          let par = this.formInfo;
          if (this.formInfo.id!=null&&this.formInfo.id!="") {
            modifyInfo(par).then(response => {
              let data = response.data;
              if (data.Code === 1000) {
                self.$messageTip.success(data.Msg); 
                self.$emit("callBack", data.Code);
              } else {
                self.$messageTip.warning(data.Msg);
              }
            });
          } else {
            addInfo(par).then(response => {
              let data = response.data;
              if (data.Code === 1000) {
                self.$messageTip.success(data.Msg); 
                self.$emit("callBack", data.Code);
              } else {
                self.$messageTip.warning(data.Msg); 
              }
            });
          }
        } else {
          return false;
        }
      });
    }
  }
};
</script>